package il.technion.cs236369.webserver;

import java.util.Collection;
import java.util.Map;

/**
 * Type Handler Container.
 * Contains TypeHandler's relevant information.
 * @author gil
 *
 */
public class TypeHandlerContainer {
	final private Class<?> _class;
	final private Map<String, String> _parameters;
	final private Collection<String> _extensions;
//	private ITypeHandler _handler = null;
	
	/**
	 * Creates a new TypeHandler container.
	 * @param c The handler's class.
	 * @param parameters The constructor's parameters.
	 * @param extensions The handler's relevant file extensions to handle.
	 */
	public TypeHandlerContainer(Class<?> c, Map<String, String> parameters, Collection<String> extensions) {
		super();
		this._class = c;
		this._parameters = parameters;
		this._extensions = extensions;
	}

//	public ITypeHandler getHandler() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
//		if (_handler != null) {
//			Common.getOut().println("Returning specific handler... (already created)");
//			return _handler;
//		}
//		Common.getOut().println("Creating specific handler...");
//		//get the ctor
//		Constructor<?> ctor = _class.getConstructor(Properties.class);
//		Properties props = new Properties();
//		//add each parameters that was predefined in the configuration
//		for (String key : _parameters.keySet()) {
//			Common.getOut().println("param name="+key+", value="+_parameters.get(key));
//			props.setProperty(key, _parameters.get(key));
//		}
//		//add the session parameter
//		//			props.put("session", new SessionImpl());
//		_handler = (ITypeHandler)ctor.newInstance(props);
//		return _handler;
//	}
	
	/**
	 * @return the _extensions
	 */
	public Collection<String> getExtensions() {
		return _extensions;
	}

	/**
	 * @return the _class
	 */
	public Class<?> getHandlerClass() {
		return _class;
	}

	/**
	 * @return the _extensions
	 */
	public Map<String, String> getParameters() {
		return _parameters;
	}
	
	

}
